package com.firefly.service.query.cms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.cms.mapper.AdMapper;
import com.firefly.dao.dao.cms.po.AdPo;
import com.firefly.dao.dao.cms.service.AdService;
import com.firefly.dao.assembler.cms.AdAssembler;
import com.firefly.dao.dto.cms.AdSearchDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.cms.AdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 广告
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/18
 **/
@Service
public class AdQuery {
    private final AdAssembler adAssembler;
    private final AdMapper adMapper;
    private final AdService adService;
    @Autowired
    public AdQuery(AdAssembler adAssembler,AdMapper adMapper,AdService adService){
        this.adAssembler = adAssembler;
        this.adMapper = adMapper;
        this.adService = adService;
    }
    // 获取列表
    public CommonListVo getList(AdSearchDto request) {
        QueryWrapper<AdPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(request.key != "", "title", request.key).eq("del_flag",0);
        Long count = adService.count(queryWrapper);
        List<AdVo> list = adMapper.getListAndPos(request);
        CommonListVo result = new CommonListVo();
        result.setCount(count);
        result.setList(list);
        return result;
    }

    public AdVo detail(int id){
        return adAssembler.getVo(adService.getById(id));
    }
}
